<?php
class Model_StudentMember extends CCMIS_Model {
    //Database student_member
	public function __construct(){
		parent::__construct();
                
        $this->load->database();
	}

    public function check_account($username, $password)
    {
        $accounts = $this->getAll();

        foreach($accounts as $account)
        {
            if($account['Username'] == $username)
            {
                if($account['Password'] == $password)
                {
                    return array("status" => "true", "username" => $account['Username'], "user_id" => $account['StudentMemberID']);
                }
                else
                {
                    return array("status" => false, "message" => 'Account found; Incorrect Password.');
                }
            }
        }
        return array("status" => false, 'message' => 'Account not found');
    }

    public function getAll()
    {
        $sql = "SELECT * FROM student_member";
        $query =  $this->db->query($sql);
        $result = $query->result_array();
        return $result;
    }

    public function getIdByUsernameOrReturnFalse($username)
    {
        $sql = "SELECT * FROM student_member WHERE Username LIKE ?";
        $query =  $this->db->query($sql, $username);
        $result = $query->row_array();

        if($query->num_rows() <= 0)
            return false;
        else
            return $result['StudentMemberID'];
    }



}
